home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / bagman.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  166 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *bagman_video_enable;
  15. static int flipscreen[2];
  16.  
  17. /***************************************************************************
  18.  
  19.   Convert the color PROMs into a more useable format.
  20.  
  21.   Bagman has two 32 bytes palette PROMs, connected to the RGB output this
  22.   way:
  23.  
  24.   bit 7 -- 220 ohm resistor  -- BLUE
  25.         -- 470 ohm resistor  -- BLUE
  26.         -- 220 ohm resistor  -- GREEN
  27.         -- 470 ohm resistor  -- GREEN
  28.         -- 1  kohm resistor  -- GREEN
  29.         -- 220 ohm resistor  -- RED
  30.         -- 470 ohm resistor  -- RED
  31.   bit 0 -- 1  kohm resistor  -- RED
  32.  
  33. ***************************************************************************/
  34. void bagman_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  35. {
  36.     int i;
  37.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  38.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  39.  
  40.  
  41.     for (i = 0;i < Machine->drv->total_colors;i++)
  42.     {
  43.         int bit0,bit1,bit2;
  44.  
  45.  
  46.         /* red component */
  47.         bit0 = (*color_prom >> 0) & 0x01;
  48.         bit1 = (*color_prom >> 1) & 0x01;
  49.         bit2 = (*color_prom >> 2) & 0x01;
  50.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  51.         /* green component */
  52.         bit0 = (*color_prom >> 3) & 0x01;
  53.         bit1 = (*color_prom >> 4) & 0x01;
  54.         bit2 = (*color_prom >> 5) & 0x01;
  55.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  56.         /* blue component */
  57.         bit0 = 0;
  58.         bit1 = (*color_prom >> 6) & 0x01;
  59.         bit2 = (*color_prom >> 7) & 0x01;
  60.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  61.  
  62.         color_prom++;
  63.     }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. WRITE_HANDLER( bagman_flipscreen_w )
  71. {
  72.     if ((data & 1) != flipscreen[offset])
  73.     {
  74.         flipscreen[offset] = data & 1;
  75.         memset(dirtybuffer,1,videoram_size);
  76.     }
  77. }
  78.  
  79.  
  80.  
  81. /***************************************************************************
  82.  
  83.   Draw the game screen in the given osd_bitmap.
  84.   Do NOT call osd_update_display() from this function, it will be called by
  85.   the main emulation engine.
  86.  
  87. ***************************************************************************/
  88. void bagman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  89. {
  90.     int offs;
  91.  
  92.  
  93.     if (*bagman_video_enable == 0)
  94.     {
  95.         fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  96.  
  97.         return;
  98.     }
  99.  
  100.  
  101.     /* for every character in the Video RAM, check if it has been modified */
  102.     /* since last time and update it accordingly. */
  103.     for (offs = videoram_size - 1;offs >= 0;offs--)
  104.     {
  105.         if (dirtybuffer[offs])
  106.         {
  107.             int sx,sy;
  108.             int bank;
  109.  
  110.  
  111.             dirtybuffer[offs] = 0;
  112.  
  113.             sx = offs % 32;
  114.             if (flipscreen[0]) sx = 31 - sx;
  115.             sy = offs / 32;
  116.             if (flipscreen[1]) sy = 31 - sy;
  117.  
  118.             /* Pickin' doesn't have the second char bank */
  119.             bank = 0;
  120.             if (Machine->gfx[2] && (colorram[offs] & 0x10)) bank = 2;
  121.  
  122.             drawgfx(tmpbitmap,Machine->gfx[bank],
  123.                     videoram[offs] + 8 * (colorram[offs] & 0x20),
  124.                     colorram[offs] & 0x0f,
  125.                     flipscreen[0],flipscreen[1],
  126.                     8*sx,8*sy,
  127.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  128.         }
  129.     }
  130.  
  131.  
  132.     /* copy the character mapped graphics */
  133.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  134.  
  135.  
  136.     /* Draw the sprites. */
  137.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  138.     {
  139.         int sx,sy,flipx,flipy;
  140.  
  141.  
  142.         sx = spriteram[offs + 3];
  143.         sy = 240 - spriteram[offs + 2];
  144.         flipx = spriteram[offs] & 0x40;
  145.         flipy = spriteram[offs] & 0x80;
  146.         if (flipscreen[0])
  147.         {
  148.             sx = 240 - sx +1;    /* compensate misplacement */
  149.             flipx = !flipx;
  150.         }
  151.         if (flipscreen[1])
  152.         {
  153.             sy = 240 - sy;
  154.             flipy = !flipy;
  155.         }
  156.  
  157.         if (spriteram[offs + 2] && spriteram[offs + 3])
  158.             drawgfx(bitmap,Machine->gfx[1],
  159.                     (spriteram[offs] & 0x3f) + 2 * (spriteram[offs + 1] & 0x20),
  160.                     spriteram[offs + 1] & 0x1f,
  161.                     flipx,flipy,
  162.                     sx,sy+1,    /* compensate misplacement */
  163.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  164.     }
  165. }
  166.